import 'package:flutter/material.dart';
import '../Pages/box.dart';
import '../Pages/Tips.dart';
import '../Pages/WarningPage.dart';
import '../Pages/AddRemind.dart';
import '../Pages/remind.dart';
import '../Pages/MyChat.dart';
import '../Pages/ChatHome.dart';
import '../Pages/Medicinebox.dart';
void main() => runApp(MyCenter());

class MyCenter extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '个人功能中心',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(),
      routes: {
        'Box':(context)=>SelectPage(),
        'Tips':(context)=>Tips(),
        'WarningPage':(context)=>WarningPage(),
        //'addRemind':(context)=>addRemind(),
        'Remind':(context)=>Remind(),
        'ChatScreen':(context)=>ChatScreen(),
        'ChatHome':(context)=>ChatHomeScreen(),
      },
    );
  }
}

/// 颜色
const List<Color> COLORS = [
  Color(0xFFFF4777),
  Color(0xFFCA6924),
  Color(0xFF00BC12),
  Color(0xFF725E82),
  Color(0xFFFFA400),
  Color(0xFFDD7160),
  Color(0xFF5D513C),
  Color(0xFFD180D2),
];

/// 例子
const DEMOS = [
  Demo(
    title: '药箱',
    description: '贴心小药箱',
    routeName: 'Box',
  ),
  Demo(
    title: '医学小贴士',
    description: '医学小贴士',
    routeName: 'Tips',
  ),
  Demo(
    title: '专家问诊',
    description: '专家问诊',
    routeName: 'ChatHome',
  ),
  Demo(
    title: '医药商城',
    description: '医学商城',
    routeName: 'Remind',
  ),

];

class Demo {
  /// 标题
  final String title;

  /// 描述
  final String description;

  /// 路由名
  final String routeName;

  const Demo({
    this.title,
    this.description,
    this.routeName,
  });
}


_mySliverAppBar() {
  return SliverAppBar(
    expandedHeight: 250,
    flexibleSpace: FlexibleSpaceBar(
      background:Image.asset("assets/images/doctor.png"),
      //new Image(image: new NetworkImage('http://n.sinaimg.cn/sports/2_img/upload/cf0d0fdd/107/w1024h683/20181128/pKtl-hphsupx4744393.jpg')),
      collapseMode: CollapseMode.parallax,
    ),
  );
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      /*appBar: AppBar(
        centerTitle: true,
        title: Text('Flutter Training'),
      ),*/

      body: GridView.builder(
        itemCount: DEMOS.length,
        padding: EdgeInsets.all(16),
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 2,
          crossAxisSpacing: 16,
          mainAxisSpacing: 16,
          childAspectRatio: 1.0,
        ),
        itemBuilder: (context, index) {
          return FlatButton(
            //onPressed: () => Navigator.pushNamed(context, DEMOS[index].routeName),
            onPressed:() {
              //Navigator.of(context).pushNamed('Medicinebox');//点击跳转界面
              Navigator.of(context).pushNamed( DEMOS[index].routeName);//点击跳转界面
            },
            color: COLORS[index % COLORS.length],
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8),
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: Center(
                    child: Text(
                      DEMOS[index].title,
                      style: TextStyle(
                        fontSize: 20,
                        fontWeight: FontWeight.bold,
                        color: Colors.white,
                      ),
                    ),
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: Text(
                    DEMOS[index].description,
                    maxLines: 3,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      fontSize: 14,
                      fontWeight: FontWeight.bold,
                      color: Colors.white70,
                    ),
                  ),
                ),
              ],
            ),
          );
        },
      ),
    );
  }
}
